<?php

class Admin_OfferTemplateController extends My_Controller_ActionAdmin {

    public function init() {
        parent::init();
        $this->view->menuSelected = 'offer';
        $this->view->submenuSelected = 'category-' . $this->_request->getActionName();
    }

    public function saveAction() {
        $code = $this->_getParam('id');
        $isEdit = false;
        $daocategory = new Application_Model_DAO_Category();
        $category = $daocategory->getByCode($code);
        $form = new Admin_Form_OfferTemplate_Add($category['offer_template_id']);
        $form->getElement('id')->setValue($code);
        
        if (!$this->_request->isPost() || !$form->isValid($_POST)) {
            $this->view->form = $form;
            $this->renderForm();
            return;
        }
        $data = $form->getValues();

        $daoOfferTemplate = new Application_Model_DAO_OfferTemplate();
        $daoOfferTemplate->addNew($category['category_id'], $data['attributes']);

        $this->addSuccess($this->translate('XXX_ADMIN_OFFER_TEMPLATE_ADD_SUCCESS'));
        $url = $this->url(array('controller' => 'offer-category', 'action' => 'index'));
        $this->_redirect($url);
    }

}

